package com.example.interfacedesign;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.Timer;
import java.util.TimerTask;


public class UC3 extends AppCompatActivity {

    //建立存储ImageView名的数组
    int [] viewNames=new int [] {
            R.id.image_view1,
            R.id.image_view2,
            R.id.image_view3,
            R.id.image_view4,
            R.id.image_view5,};

    //建立存储ImageView的数组
    private ImageView [] views=new ImageView[viewNames.length];
    int currentView=0;

    //运用Handler让ImageView依次显示
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 0x123) {
                //do
                views[currentView].bringToFront();
                if(currentView==4)  currentView=0;
                else currentView++;
            }
            super.handleMessage(msg);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uc3);

        for (int i=0;i<viewNames.length;i++){
            views[i]=(ImageView) findViewById(viewNames[i]);
        }

        //用Timer定时器间隔调用handler
        new Timer().schedule(new TimerTask()
        {
                @Override
                public void run() {
                        handler.sendEmptyMessage(0x123);
                }
                },0,1500);

        //返回按钮
        Button button_return=findViewById(R.id.button_return);

        button_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(UC3.this,MainActivity.class);
                startActivity(intent);
            }
        });
    }
}

